home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / enumfo1r / calculat.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-08-06  |  12.5 KB  |  429 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Easy Calculator"
  4.    ClientHeight    =   3990
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   5400
  8.    BeginProperty Font 
  9.       Name            =   "Verdana"
  10.       Size            =   9.75
  11.       Charset         =   0
  12.       Weight          =   400
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    Icon            =   "calculator.frx":0000
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   3990
  20.    ScaleWidth      =   5400
  21.    StartUpPosition =   3  'Windows Default
  22.    Begin VB.CommandButton cmdSin 
  23.       Caption         =   "Sin"
  24.       Height          =   540
  25.       Left            =   3675
  26.       TabIndex        =   30
  27.       Top             =   1995
  28.       Width           =   540
  29.    End
  30.    Begin VB.CommandButton cmdCos 
  31.       Caption         =   "Cos"
  32.       Height          =   540
  33.       Left            =   3675
  34.       TabIndex        =   29
  35.       Top             =   1365
  36.       Width           =   540
  37.    End
  38.    Begin VB.CommandButton cmdSquareRoot 
  39.       Caption         =   "sqrt"
  40.       Height          =   540
  41.       Left            =   3675
  42.       TabIndex        =   28
  43.       Top             =   735
  44.       Width           =   540
  45.    End
  46.    Begin VB.Frame Frame2 
  47.       Caption         =   "Memory Contents"
  48.       BeginProperty Font 
  49.          Name            =   "Verdana"
  50.          Size            =   8.25
  51.          Charset         =   0
  52.          Weight          =   400
  53.          Underline       =   0   'False
  54.          Italic          =   0   'False
  55.          Strikethrough   =   0   'False
  56.       EndProperty
  57.       Height          =   645
  58.       Left            =   2730
  59.       TabIndex        =   26
  60.       Top             =   3255
  61.       Width           =   2535
  62.       Begin VB.Label lblMemory1 
  63.          BackColor       =   &H00000000&
  64.          BorderStyle     =   1  'Fixed Single
  65.          ForeColor       =   &H0000FF00&
  66.          Height          =   330
  67.          Left            =   105
  68.          TabIndex        =   27
  69.          Top             =   210
  70.          Width           =   2325
  71.       End
  72.    End
  73.    Begin VB.CommandButton cmdMemory3 
  74.       Caption         =   "MC"
  75.       Height          =   435
  76.       Left            =   4830
  77.       TabIndex        =   25
  78.       Top             =   1680
  79.       Width           =   540
  80.    End
  81.    Begin VB.CommandButton cmdMemory2 
  82.       Caption         =   "MR"
  83.       Height          =   435
  84.       Left            =   4830
  85.       TabIndex        =   24
  86.       Top             =   2205
  87.       Width           =   540
  88.    End
  89.    Begin VB.CommandButton cmdMemory1 
  90.       Caption         =   "M+"
  91.       Height          =   435
  92.       Left            =   4830
  93.       TabIndex        =   23
  94.       Top             =   2730
  95.       Width           =   540
  96.    End
  97.    Begin VB.Frame Frame1 
  98.       Caption         =   "Running Total"
  99.       BeginProperty Font 
  100.          Name            =   "Verdana"
  101.          Size            =   8.25
  102.          Charset         =   0
  103.          Weight          =   400
  104.          Underline       =   0   'False
  105.          Italic          =   0   'False
  106.          Strikethrough   =   0   'False
  107.       EndProperty
  108.       Height          =   645
  109.       Left            =   98
  110.       TabIndex        =   21
  111.       Top             =   3255
  112.       Width           =   2535
  113.       Begin VB.Label lblRunning 
  114.          BackColor       =   &H00000000&
  115.          BorderStyle     =   1  'Fixed Single
  116.          ForeColor       =   &H0000FF00&
  117.          Height          =   330
  118.          Left            =   105
  119.          TabIndex        =   22
  120.          Top             =   210
  121.          Width           =   2325
  122.       End
  123.    End
  124.    Begin VB.CommandButton cmdClearAll 
  125.       Caption         =   "CA"
  126.       Height          =   435
  127.       Left            =   4830
  128.       TabIndex        =   20
  129.       Top             =   735
  130.       Width           =   540
  131.    End
  132.    Begin VB.CommandButton cmdEquals 
  133.       Caption         =   "="
  134.       Height          =   540
  135.       Left            =   2415
  136.       TabIndex        =   19
  137.       Top             =   2625
  138.       Width           =   1170
  139.    End
  140.    Begin VB.CommandButton cmdDivide 
  141.       Caption         =   "/"
  142.       Height          =   540
  143.       Left            =   3045
  144.       TabIndex        =   18
  145.       Top             =   1995
  146.       Width           =   540
  147.    End
  148.    Begin VB.CommandButton cmdTimes 
  149.       Caption         =   "*"
  150.       Height          =   540
  151.       Left            =   2415
  152.       TabIndex        =   17
  153.       Top             =   1995
  154.       Width           =   540
  155.    End
  156.    Begin VB.CommandButton cmdMinus 
  157.       Caption         =   "-"
  158.       Height          =   540
  159.       Left            =   3045
  160.       TabIndex        =   16
  161.       Top             =   1365
  162.       Width           =   540
  163.    End
  164.    Begin VB.CommandButton cmdPlusMinus 
  165.       Caption         =   "+/-"
  166.       Height          =   540
  167.       Left            =   2415
  168.       TabIndex        =   15
  169.       Top             =   735
  170.       Width           =   540
  171.    End
  172.    Begin VB.CommandButton cmdOver 
  173.       Caption         =   "1/X"
  174.       Height          =   540
  175.       Left            =   3045
  176.       TabIndex        =   14
  177.       Top             =   735
  178.       Width           =   540
  179.    End
  180.    Begin VB.CommandButton cmdPlus 
  181.       Caption         =   "+"
  182.       Height          =   540
  183.       Left            =   2415
  184.       TabIndex        =   13
  185.       Top             =   1365
  186.       Width           =   540
  187.    End
  188.    Begin VB.CommandButton Command1 
  189.       Caption         =   "."
  190.       BeginProperty Font 
  191.          Name            =   "Verdana"
  192.          Size            =   14.25
  193.          Charset         =   0
  194.          Weight          =   400
  195.          Underline       =   0   'False
  196.          Italic          =   0   'False
  197.          Strikethrough   =   0   'False
  198.       EndProperty
  199.       Height          =   540
  200.       Left            =   1470
  201.       TabIndex        =   12
  202.       Top             =   2625
  203.       Width           =   540
  204.    End
  205.    Begin VB.CommandButton cmdClear 
  206.       Caption         =   "CE"
  207.       Height          =   435
  208.       Left            =   4830
  209.       TabIndex        =   11
  210.       Top             =   210
  211.       Width           =   540
  212.    End
  213.    Begin VB.CommandButton cmdDigits 
  214.       Caption         =   "9"
  215.       Height          =   540
  216.       Index           =   9
  217.       Left            =   1470
  218.       TabIndex        =   10
  219.       Top             =   1995
  220.       Width           =   540
  221.    End
  222.    Begin VB.CommandButton cmdDigits 
  223.       Caption         =   "8"
  224.       Height          =   540
  225.       Index           =   8
  226.       Left            =   840
  227.       TabIndex        =   9
  228.       Top             =   1995
  229.       Width           =   540
  230.    End
  231.    Begin VB.CommandButton cmdDigits 
  232.       Caption         =   "7"
  233.       Height          =   540
  234.       Index           =   7
  235.       Left            =   210
  236.       TabIndex        =   8
  237.       Top             =   1995
  238.       Width           =   540
  239.    End
  240.    Begin VB.CommandButton cmdDigits 
  241.       Caption         =   "6"
  242.       Height          =   540
  243.       Index           =   6
  244.       Left            =   1470
  245.       TabIndex        =   7
  246.       Top             =   1365
  247.       Width           =   540
  248.    End
  249.    Begin VB.CommandButton cmdDigits 
  250.       Caption         =   "5"
  251.       Height          =   540
  252.       Index           =   5
  253.       Left            =   840
  254.       TabIndex        =   6
  255.       Top             =   1365
  256.       Width           =   540
  257.    End
  258.    Begin VB.CommandButton cmdDigits 
  259.       Caption         =   "4"
  260.       Height          =   540
  261.       Index           =   4
  262.       Left            =   210
  263.       TabIndex        =   5
  264.       Top             =   1365
  265.       Width           =   540
  266.    End
  267.    Begin VB.CommandButton cmdDigits 
  268.       Caption         =   "3"
  269.       Height          =   540
  270.       Index           =   3
  271.       Left            =   1470
  272.       TabIndex        =   4
  273.       Top             =   735
  274.       Width           =   540
  275.    End
  276.    Begin VB.CommandButton cmdDigits 
  277.       Caption         =   "2"
  278.       Height          =   540
  279.       Index           =   2
  280.       Left            =   840
  281.       TabIndex        =   3
  282.       Top             =   735
  283.       Width           =   540
  284.    End
  285.    Begin VB.CommandButton cmdDigits 
  286.       Caption         =   "1"
  287.       Height          =   540
  288.       Index           =   1
  289.       Left            =   210
  290.       TabIndex        =   2
  291.       Top             =   735
  292.       Width           =   540
  293.    End
  294.    Begin VB.CommandButton cmdDigits 
  295.       Caption         =   "0"
  296.       Height          =   540
  297.       Index           =   0
  298.       Left            =   210
  299.       TabIndex        =   1
  300.       Top             =   2625
  301.       Width           =   540
  302.    End
  303.    Begin VB.Label lblDisplay 
  304.       BackColor       =   &H00000000&
  305.       BorderStyle     =   1  'Fixed Single
  306.       BeginProperty Font 
  307.          Name            =   "Verdana"
  308.          Size            =   18
  309.          Charset         =   0
  310.          Weight          =   400
  311.          Underline       =   0   'False
  312.          Italic          =   0   'False
  313.          Strikethrough   =   0   'False
  314.       EndProperty
  315.       ForeColor       =   &H0000FF00&
  316.       Height          =   435
  317.       Left            =   165
  318.       TabIndex        =   0
  319.       Top             =   210
  320.       Width           =   4590
  321.    End
  322. Attribute VB_Name = "Form1"
  323. Attribute VB_GlobalNameSpace = False
  324. Attribute VB_Creatable = False
  325. Attribute VB_PredeclaredId = True
  326. Attribute VB_Exposed = False
  327. Option Explicit
  328. Dim operand1 As Double, operand2 As Double
  329. Dim operator As String
  330. Dim cleardisplay As Boolean
  331. Dim memory1 As Double
  332. Dim percent As Double
  333. Private Sub cmdClear_Click()
  334. lblDisplay.Caption = ""
  335. End Sub
  336. Private Sub cmdClearAll_Click()
  337. operand1 = 0
  338. operand2 = 0
  339. lblDisplay.Caption = ""
  340. lblRunning.Caption = ""
  341. End Sub
  342. Private Sub cmdCos_Click()
  343. lblDisplay.Caption = Cos(Val(lblDisplay.Caption))
  344. End Sub
  345. Private Sub cmdDigits_Click(Index As Integer)
  346. If cleardisplay Then
  347.     lblDisplay.Caption = ""
  348.     cleardisplay = False
  349. End If
  350. If Len(lblDisplay.Caption) < 10 Then
  351.    lblDisplay.Caption = lblDisplay.Caption + cmdDigits(Index).Caption
  352.     Else
  353.     End If
  354. End Sub
  355. Private Sub cmdDivide_Click()
  356. operand1 = Val(lblDisplay.Caption)
  357. operator = "/"
  358. lblDisplay.Caption = ""
  359. End Sub
  360. Private Sub cmdEquals_Click()
  361. On Error GoTo errorhandler
  362. Dim result As Double
  363. operand2 = Val(lblDisplay.Caption)
  364. If operator = "+" Then result = operand1 + operand2
  365. If operator = "-" Then result = operand1 - operand2
  366. If operator = "*" Then result = operand1 * operand2
  367. If operator = "/" And operand2 <> "0" Then _
  368.                 result = operand1 / operand2
  369. lblDisplay.Caption = result
  370. operand1 = result
  371. lblRunning.Caption = result
  372. Exit Sub
  373. errorhandler:
  374. MsgBox "The operation resulted in the following error" & _
  375.     vbCrLf & Err.Description
  376. lblDisplay.Caption = "ERROR"
  377. cleardisplay = True
  378. End Sub
  379. Private Sub cmdMemory1_Click()
  380. memory1 = lblDisplay.Caption
  381. lblMemory1 = memory1
  382. End Sub
  383. Private Sub cmdMemory2_Click()
  384. lblDisplay.Caption = memory1
  385. End Sub
  386. Private Sub cmdMemory3_Click()
  387. memory1 = 0
  388. lblMemory1.Caption = ""
  389. End Sub
  390. Private Sub cmdMinus_Click()
  391. operand1 = Val(lblDisplay.Caption)
  392. operator = "-"
  393. lblDisplay.Caption = ""
  394. End Sub
  395. Private Sub cmdOver_Click()
  396. If Val(lblDisplay.Caption) <> 0 Then lblDisplay.Caption = _
  397.                         1 / Val(lblDisplay.Caption)
  398.                         
  399. End Sub
  400. Private Sub cmdPlus_Click()
  401. operand1 = Val(lblDisplay.Caption)
  402. operator = "+"
  403. lblDisplay.Caption = ""
  404. lblRunning.Caption = operand1
  405. End Sub
  406. Private Sub cmdPlusMinus_Click()
  407. lblDisplay.Caption = -Val(lblDisplay.Caption)
  408. End Sub
  409. Private Sub cmdSin_Click()
  410. lblDisplay.Caption = Sin(Val(lblDisplay.Caption))
  411. End Sub
  412. Private Sub cmdSquareRoot_Click()
  413. If lblDisplay.Caption < 0 Then
  414. MsgBox "Can't calculate the square root of a negative number"
  415. lblDisplay.Caption = Sqr(Val(lblDisplay.Caption))
  416. End If
  417. End Sub
  418. Private Sub cmdTimes_Click()
  419. operand1 = Val(lblDisplay.Caption)
  420. operator = "*"
  421. lblDisplay.Caption = ""
  422. End Sub
  423. Private Sub Command1_Click()
  424. If InStr(lblDisplay.Caption, ".") Then
  425.     Exit Sub
  426.     lblDisplay.Caption = lblDisplay.Caption + "."
  427. End If
  428. End Sub
  429.